<?php
/**
 * 项目操作类
 *
 */
class ProjectClass extends FrameWork {
	/**
	 * 信息列表 
	 * @author workflow Develop Team     
	 * @param  $condition,$obj_page
	 * @return array
	 */
	function listProject($condition,&$obj_page){
		//$project_array = $GLOBALS['db']->GetList($condition, $obj_page, "project");
		$project_array = $GLOBALS['db']->GetJoinList($obj_page, array('project', 'company', 'customer'), "left join", array("project.company_id=company.id", "project.customer_id=customer.id"), array('*', 'realname as company_name', 'realname as customer_name'), $condition);
		return $project_array;
	}
	
	/**
	 * 信息添加 
	 * @author workflow Develop Team     
	 * @param  $value_array
	 * @return bool
	 */
	function addProject($value_array){
		if (is_array($value_array)){
			$valueArray = array();
			foreach ($value_array as $k => $v){
				if ($v != ''){
					$valueArray[$k] = $v;
				}
			}
			$result = $GLOBALS['db']->InsertRow($valueArray,"project","id");
			unset($value_array,$valueArray);
			return $result;
		}
		return false;
	}
	
	/**
	 * 取信息
	 * @author workflow Develop Team     
	 * @param  $id
	 * @return array
	 */
	function getProject($id,$type='simple'){
		if (intval($id) > 0){
			if ($type == 'simple'){
				$value_array = $GLOBALS['db']->GetOneRow(intval($id),'project','id');
			}else if ($type == 'more'){
				//$obj_page, array('project', 'company', 'customer'), "left join", array("project.company_id=company.id", "project.customer_id=customer.id"), array('*', 'realname as company_name', 'realname as customer_name'), $condition);
				$value_array = $GLOBALS['db']->GetOneJoinArray(array('project', 'company', 'customer', 'system_member'), "left join", array("project.company_id=company.id", "project.customer_id=customer.id", "project.user_id=system_member.sys_member_id"),array('*', 'realname as company_name, address as company_address, website as company_website', 'realname as customer_name, jobname as customer_jobname, office_call as customer_officecall', 'real_name as user_name'),"and project.id='". intval($id) ."'");
			}
			return $value_array;
		}
		return false;
	}
	
	/**
	 * 修改信息
	 * @author workflow Develop Team     
	 * @param  $value_array
	 * @return bool
	 */
	function updateProject($value_array){
		if (is_array($value_array) && intval($value_array['id']) > 0){
			$valueArray = array();
			foreach ($value_array as $k => $v){
				$valueArray[$k] = $v;
			}
			$result = $GLOBALS['db']->UpdateRow(intval($valueArray['id']), $valueArray, 'project', 'id');
			unset($value_array,$valueArray);
			return $result;
		}
		return false;
	}
	
	/**
	 * 删除信息
	 * @author workflow Develop Team     
	 * @param  $id
	 * @return bool
	 */
	function delProject($id){
		if (intval($id) > 0){
			//$result = $GLOBALS['db']->DeleOneRow(intval($id),'project','id');
			$valueArray = array();
			$valueArray['id'] = $id;
			$valueArray['status'] = 0;
			$result = $GLOBALS['db']->UpdateRow(intval($id), $valueArray, 'project', 'id');
			unset($valueArray);
			return $result;
		}
		return false;
	}
}
?>